package com.phiture.erp.produce.dal.mapper;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.phiture.erp.produce.common.enums.MrpReleaseStatusEnum;
import com.phiture.erp.produce.dal.entity.ErpMaterialRequirementPlanItemsDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 物料需求计划明细 Mapper
 *
 * @author YH
 */
@Mapper
public interface ErpMaterialRequirementPlanItemsMapper extends BaseMapperX<ErpMaterialRequirementPlanItemsDO> {

    default List<ErpMaterialRequirementPlanItemsDO> selectListByMaterialRequirementPlanIds(Collection<Long> ids) {
        return selectList(ErpMaterialRequirementPlanItemsDO::getMaterialRequirementPlanId, ids);
    }

    default int deleteByMaterialRequirementPlanId(Long materialRequirementPlanId) {
        return delete(ErpMaterialRequirementPlanItemsDO::getMaterialRequirementPlanId, materialRequirementPlanId);
    }

    default boolean existsReleasedData(Long materialRequirementPlanId){
        return exists(
                Wrappers.lambdaQuery(ErpMaterialRequirementPlanItemsDO.class)
                        .eq(ErpMaterialRequirementPlanItemsDO::getMaterialRequirementPlanId, materialRequirementPlanId)
                        .eq(ErpMaterialRequirementPlanItemsDO::getStatus, MrpReleaseStatusEnum.RELEASED.getStatus())
                        .eq(ErpMaterialRequirementPlanItemsDO::getDeleted, Boolean.FALSE)
        );
    }

}
